home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / lockIntersections.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  2.6 KB  |  89 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17.  
  18. global proc int lockIntersections()
  19. //
  20. //    Description :
  21. //        Select two or more curve param point or edit points
  22. //        and lock these points together to ensure an intersection.
  23. //        NOTE: Works of the selection list.
  24. //
  25. {
  26.     string $curveNames[] ;
  27.     string $locators[] ;
  28.     string $lsqNodes[] ;
  29.     int $len ;
  30.     int $i ;
  31.  
  32.     int $ok = 1 ;
  33.     int $sc = 0 ;
  34.  
  35.     $curveNames = `ls -sl` ;
  36.     $len = size($curveNames) ;
  37.     if( $len == 0 ) return 0 ;
  38.  
  39.     // run filter to get only items of interest.
  40.     //
  41.     global int $gSelectEditPointsBit ;
  42.     global int $gSelectCurveParmPointsBit ;
  43.     string $curveNames[] = `filterExpand -ex true -sm $gSelectEditPointsBit -sm $gSelectCurveParmPointsBit $curveNames`;    
  44.  
  45.     $len = size($curveNames) ;
  46.     if( $len == 0 ) return 0 ;
  47.     if( $ok ) {
  48.  
  49.         for( $i = 0 ; $i < $len ; $i++ ) {
  50.             string $name = $curveNames[$i] ;
  51.             string $tmpResults[] ;
  52.             if( catch( $tmpResults = `pointCurveConstraint -ch 1 -rpo 1 $name` ) ) {
  53.                 $ok = 0 ;
  54.                 $sc = 1 ;
  55.             } else {
  56.                 $locators[$i] = $tmpResults[0] ;
  57.                 $lsqNodes[$i] = $tmpResults[1] ;    
  58.             }
  59.         }
  60.     }    
  61.  
  62.     // 
  63.     // Disconnect all locators but locator [0].
  64.     // locator[0].wp[0] now fans out to all other nodes.
  65.     // That way we have one locator controlling the position
  66.     // of the intersection point.
  67.     //
  68.     string $inAttr  ;
  69.     if( $ok ) {
  70.         $len = size($locators) ;
  71.  
  72.         string $newSrc = $locators[0] + ".wp[0]" ;
  73.         for( $i = 1 ; $i < $len ; $i++ ) {
  74.             string $dests[] ;    
  75.             string $locName = $locators[$i] ;
  76.             $inAttr = $locName + ".wp[0]" ;
  77.             $dests = `listConnections -p true $inAttr` ;
  78.             if( size($dests) > 0 ) {
  79.                 disconnectAttr $inAttr $dests[0] ;
  80.                 connectAttr $newSrc $dests[0] ;
  81.             }
  82.             delete $locName ;
  83.         }
  84.         select -r $locators[0] ;
  85.     }
  86.     if( $ok != 1 ) $sc = $ok ;
  87.     return $sc ;
  88.